<template>
  <div class="login-wrap">
    <div class="ms-title">网关管理系统</div>
    <div class="ms-login">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="demo-ruleForm">
        <el-form-item prop="userId">
          <el-input v-model="ruleForm.userId" placeholder="username" @keyup.enter.native="next()"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" placeholder="password" v-model="ruleForm.password"
                    @keyup.enter.native="submitForm()" ref="password"></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>


<script>
  // import api from '../../api/loginHome/apiLogin'
  // import md5 from 'js-md5'
  export default {
    data: function () {
      return {
        ruleForm: {
          userName: '',
          passWord: ''
        },
        rules: {
          userName: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          passWord: [
            {required: true, message: '请输入密码', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      // 点击跳转到注册界面
      toRegister () {
        this.$router.push('/register')
      },
      submitForm () {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            const self = this
            let para = {
              password: self.ruleForm.passWord,
              adminName: self.ruleForm.userName
            }
            console.log('toLogin')
            console.log(para)
            self.$router.push('/home')
            /* api.toLogin(para).then(res => {
              console.log('toLogin 回参')
              console.log(res)
              if (res.result === 1000) {
                sessionStorage.setItem('isAdmin', !res.content.admin.type)
                sessionStorage.setItem('userId', res.content.admin.adminId)
                sessionStorage.setItem('userName', res.content.admin.adminName)
                self.$message.success('登录成功！')
                self.$router.push('/hardWare/gateway')
              } else {
                self.$message({
                  message: res.resultDesp,
                  type: 'error'
                })
              }
            })
            .catch(error => {
              self.$message({
                message: error,
                type: 'error'
              })
            }) */
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      next () {
        let nextInput = this.$refs['password'].$el.children[0]
        console.log(nextInput)
        nextInput.focus()
      }
    },
    mounted () {
      // this.getUserInfo()
    }
  }
</script>

<style scoped>
  .login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
  }

  .ms-title {
    position: absolute;
    top: 50%;
    width: 100%;
    margin-top: -230px;
    text-align: center;
    font-size: 30px;
    color: #fff;

  }

  .ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 300px;
    height: 160px;
    margin: -150px 0 0 -190px;
    padding: 40px;
    border-radius: 5px;
    background: #fff;
  }

  .login-btn {
    text-align: center;
  }

  .login-btn button {
    width: 100%;
    height: 36px;
  }
</style>
